<?php
/**
 * XHTML Document, body
 *
 * @package Core
 * @subpackage Document
 * 
 */
class Lead_Controller_Response_Document_Body
{
	
    
    private $_onLoad;
    
    
    /**
	 * Body class
	 *
	 * @var string
	 */
	protected $class;
	/**
	 * Body content
	 *
	 * @var string
	 */
	protected $body = '';
		
	/**
	 * Renders body.
	 *
	 * @return string
	 */
	function render()
	{
		
		$output = array();
		
		$bodytag = '';
		
		if(!preg_match('/<body/', $this->body)) {
		    $bodytag .= "<body";

		    if($this->class)
		       $bodytag .= " class=\"{$this->class}\"";
		    
		    if($this->_onLoad)
		       $bodytag .= " onload=\"{$this->_onLoad}\"";
		       
		    $bodytag .=">";
		}

		$output[] = $bodytag;
			
		
		$output[] = $this->body;

		if(!preg_match('/<\/body>/', $this->body))
			$output[] = "</body>";
		
		return implode("\n", $output);
				
	}
	
	
	/**
	 * Appends something to body.
	 *
	 * @param string $to_append String to append
	 */
	function append($to_append)
	{
		$this->body .= $to_append;
				
	}
	
	/**
	 * Prepends something to body
	 *
	 * @param string $to_prepend String to prepend
	 */
	function prepend($to_prepend)
	{
		$this->body = $to_prepend . $this->body;
	}
	
	function set($to_set)
	{
		$this->body = $to_set;
	}
	
	
	public function get()
	{
	    return $this->body;
	}
	
	
	public function onLoad($onLoad)
	{
	    $this->_onLoad = $onLoad;
	}
	
	
	
}
?>